<?php

namespace Admin\Controller;

use Think\Controller;

class LoginController extends Controller
{
    public function login()
    {
        session_start();
        $login = D('admin');
        if (IS_POST) {
            $data['name'] = I('post.name');
            $data['password'] = I('post.password');
            $data['_logic'] = 'AND';
            $res = $login->where($data)->select();
            if (!$res) {
                $this->error('登录失败！用户名或密码错误！');
            } else {
                session('user',$res);
                $this->success('登录成功！', U("Index/index"));
            }

            return;
        }
        // $sessions=session('user');
//        $this->assign('sessions',$sessions);
        $this->display();
    }
    public function out(){
        session('user',null);
        $this->success('退出成功！',U('Login/login'));
    }
}

